import 'package:color_dart/RgbaColor.dart';
import 'package:flutter/material.dart';
import 'package:im_flutter_sdk_example/jsonserialize/group/group_manager.dart';
import 'package:im_flutter_sdk_example/jsonserialize/message/data.dart';
import 'package:im_flutter_sdk_example/provider/group_formdate_model.dart';
import 'package:im_flutter_sdk_example/provider/group_message.dart';
import 'package:im_flutter_sdk_example/utils/global.dart';
import 'package:provider/provider.dart';

class GroupInfoPage extends StatelessWidget {
  Widget buildTitle(String title) {
    return Container(
      margin: EdgeInsets.symmetric(vertical: 8),
      child: Text(title,
          style: TextStyle(
              color: rgba(68, 68, 68, 1),
              fontSize: 16,
              fontWeight: FontWeight.bold)),
    );
  }

  Widget buildTeamItem({GroupManager item}) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 5),
      child: ListTile(
        title: Row(
          children: [
            Text(item.userInfo.nickname,
                style: TextStyle(color: rgba(68, 68, 68, 1), fontSize: 16)),
          ],
        ),
        leading: SizedBox(
          width: 60,
          height: 60,
          child: ClipOval(
            child: Image.network(
              item.userInfo.avatar,
              width: 30,
              height: 30,
              fit: BoxFit.cover,
            ),
          ),
        ),
      ),
    );
  }

  Widget buildDivider() {
    return Container(
      margin: EdgeInsets.all(16),
      child: Divider(color: rgba(235, 235, 235, 1), height: 1),
    );
  }

  @override
  Widget build(BuildContext context) {
    GroupMessageProvider groupMessageProvider =
        Provider.of<GroupMessageProvider>(context);
    Message message = groupMessageProvider.latestMessage;
    GroupFormDataModel groupProvider = Provider.of<GroupFormDataModel>(context);

    return Scaffold(
      appBar: AppBar(title: Text('关于小组')),
      body: SingleChildScrollView(
        padding: EdgeInsets.only(top: 10),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            message == null
                ? (G.emptyBox())
                : Padding(
                    padding: const EdgeInsets.symmetric(horizontal: 16),
                    child: Text('${message.note}',
                        style: TextStyle(
                            color: rgba(68, 68, 68, 1), fontSize: 15)),
                  ),
            buildDivider(),
            Container(
                padding: EdgeInsets.symmetric(horizontal: 20),
                child: buildTitle('管理团队')),
            Column(
                children: groupProvider.groupManager.data
                    .map((item) => buildTeamItem(item: item))
                    .toList()),
            buildDivider(),
            Container(
                padding: EdgeInsets.symmetric(horizontal: 20),
                child: buildTitle('小组网址')),
            Container(
                padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
                child: Text(groupProvider.myGroup.webLink,
                    style:
                        TextStyle(color: rgba(68, 68, 68, 1), fontSize: 14))),
          ],
        ),
      ),
    );
  }
}
